<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon
      :icon-class="isScreenFull ? 'exit-fullscreen' : 'fullscreen'"
      class="fullscreen"
      @click="toggleFull"
    />
  </div>
</template>

<script>
import screenfull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      isScreenFull: false // 是否是全屏
    }
  },

  mounted() {
    // change 监听全屏与否的状态
    screenfull.on('change', () => {
      // screenfull.isFullscreen 是插件本身给提供的全屏与否的状态
      // 如果是全屏,值为 true, 如果退出全屏, 值为 false
      this.isScreenFull = screenfull.isFullscreen
    })
  },

  methods: {
    toggleFull() {
      // toggle 方法是 screefull 提供的切换到全屏的方法
      screenfull.toggle()

      // 切换全屏与否状态
      this.isScreenFull = !this.isScreenFull
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
